﻿define(function (require) {
    require('model/Feed');
    require('model/FeedList');

    var PopupView = require('view/PopupView');
    var service = require('ezdesk/utility/service');
    var utility = require('ezdesk/utility/utility.js');

    $(function () {
        var $_self = $(this);

        $.receiveMessage(function (e) {
            var paramKeyRegex = /\w*(?=\:)/g;
            var key = paramKeyRegex.exec(e.data);
            key = key ? key[0] : e.data;

            if (key == 'refreshNotis')
                refreshNotis(e.data.substring(key.length + 1));
        });

        var popupView = new PopupView({ model: new FeedList });

        var refreshNotis = function (feedsWithNewUpdateOn) {
            feedsWithNewUpdateOn = utility.ToObject(feedsWithNewUpdateOn);

            $(feedsWithNewUpdateOn).each(function (index, item) {
                if (item.IsAvailable) {
                    popupView.model.add(item);
                }
            });
        }

    });
});
